	
	var mapContainer;
	var map;
	var current_paradas;
	var current_waypoints_ayuda;
	
	function iniciar_mapas(){
		//====================================
		//    Inicializacion Mapas		
		//====================================
		nokia.Settings.set("app_id", "DemoAppId01082013GAL"); 
		nokia.Settings.set("app_code", "AJKnXv84fjrb0KIHawS0Tg");	

		// Use staging environment (remove the line for production environment)
		nokia.Settings.set("serviceMode", "cit");

		// Get the DOM node to which we will append the map
		mapContainer = document.getElementById("mapContainer");
		// Create a map inside the map container DOM node
		map = new nokia.maps.map.Display(mapContainer, {
			// initial center and zoom level of the map
			center: [6.2359, -75.5751],
			zoomLevel: 12,
			components: [
				// ZoomBar provides a UI to zoom the map in & out
				new nokia.maps.map.component.ZoomBar(),
				new nokia.maps.map.component.Behavior()
			]	
		});
	}
	
	function coordenadas_recuperadas(data_recuperada){
		var i;
		var id_ruta = document.getElementById('id_ruta_id').value;
		
		current_waypoints_ayuda = [];
		for (i = 0; i < data_recuperada.waypoints.length; i++){
			current_waypoints_ayuda.push({
				id_waypoint_parada: data_recuperada.waypoints[i].id_waypoint_parada,
				latitud: data_recuperada.waypoints[i].latitud,
				longitud: data_recuperada.waypoints[i].longitud,
			});
		}
		
		current_paradas = [];
		for (i = 0; i < data_recuperada.paradas.length; i++){
			current_paradas.push({
				id_parada: data_recuperada.paradas[i].id_parada,
				orden_ruta: data_recuperada.paradas[i].orden_ruta,
				latitud: data_recuperada.paradas[i].latitud,
				longitud: data_recuperada.paradas[i].longitud,
				nombre_parada: data_recuperada.paradas[i].nombre_parada,
			});
		}
		
		graficarRutaParadas(id_ruta, current_paradas, current_waypoints_ayuda);
				
	}
	
	
	function graficarRutaParadas(id_ruta, paradas, waypoints_ayuda){
		var paradas_length = paradas.length;
		var waypoints_ayuda_length = waypoints_ayuda.length;

		paradas = sortObjects(paradas, "orden_ruta", true);
		waypoints_ayuda = sortObjects(waypoints_ayuda, "id_waypoint_parada", true);

		var paradas_waypoints = [];
		var waypoints_ayuda_positions = [];
		for (j in waypoints_ayuda) {
			paradas_waypoints[waypoints_ayuda[j].id_waypoint_parada - 1] = waypoints_ayuda[j];
			waypoints_ayuda_positions.push(waypoints_ayuda[j].id_waypoint_parada - 1);
		}

		var i = 0;
		for (j in paradas) {
			while (paradas_waypoints[i] !== undefined) {
				i++;
			}
			paradas_waypoints[i++] = paradas[j];
		}

		var waypoints = new nokia.maps.routing.WaypointParameterList();
		for (var i = 0; i <= paradas_length + waypoints_ayuda_length - 1; i++) {
			waypoints.addCoordinate(new nokia.maps.geo.Coordinate(Number(paradas_waypoints[i].latitud), Number(paradas_waypoints[i].longitud)));
		}

		router = new nokia.maps.routing.Manager();
		router.set("id_ruta", id_ruta);
		router.set("waypoints_ayuda_positions", waypoints_ayuda_positions);
		router.set("paradas_waypoints", paradas_waypoints);
		router.addObserver("state", onRouteCalculated);
		var mode = {
			type: "shortest", 
			transportModes: ["car"],
			trafficMode: "disabled",
			options: ""
		};
		router.calculateRoute(waypoints, mode);
	}

	function sortObjects(objects, property, asc) {
		var length = objects.length;
		if (asc == true) {
			for (var i = 0; i < length; i++) {
				for (var j = length - 1; j > i; j--) {
					if (objects[j - 1][property] > objects[j][property]) {
						var aux = objects[j - 1];
						objects[j - 1] = objects[j];
						objects[j] = aux;
					}
				};
			}
		}
		else {
			for (var i = 0; i < length; i++) {
				for (var j = length - 1; j > i; j--) {
					if (objects[j - 1][property] < objects[j][property]) {
						var aux = objects[j - 1];
						objects[j - 1] = objects[j];
						objects[j] = aux;
					}
				};
			}
		}
		return objects;
	}